package com.wgts.wgts.mvp.view.activity.shopkeeper;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AssetDetailActivity extends BaseActivity {
    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.tv_all)
    TextView tvAll;
    @BindView(R.id.tv_reward)
    TextView tvReward;
    @BindView(R.id.tv_commission)
    TextView tvCommission;
    @BindView(R.id.tv_put_forward)
    TextView tvPutForward;
    @BindView(R.id.tv_consumption)
    TextView tvConsumption;
    @BindView(R.id.view_page)
    ViewPager viewPage;
    @BindView(R.id.view_all)
    View viewAll;
    @BindView(R.id.view_reward)
    View viewReward;
    @BindView(R.id.view_commission)
    View viewCommission;
    @BindView(R.id.view_forward)
    View viewForward;
    @BindView(R.id.view_consumption)
    View viewConsumption;

    private List<Fragment> fragments;

    @Override
    public void init() {

    }

    @Override
    public void onCreate(Bundle saveInstanceBundle) {
        super.onCreate(saveInstanceBundle);
        setContentView(R.layout.asset_detail_activity);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        fragments = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            fragments.add(AssetDetailFragment.getInstance(i));
        }
        viewPage.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int i) {
                return fragments.get(i);
            }

            @Override
            public int getCount() {
                return 5;
            }
        });

        viewPage.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                releaseView();
                switch (i) {
                    case 0:
                        tvAll.setTextColor(ContextCompat.getColor(AssetDetailActivity.this, R.color.crush_red));
                        viewAll.setVisibility(View.VISIBLE);
                        break;
                    case 1:
                        tvReward.setTextColor(ContextCompat.getColor(AssetDetailActivity.this, R.color.crush_red));
                        viewReward.setVisibility(View.VISIBLE);
                        break;
                    case 2:
                        tvCommission.setTextColor(ContextCompat.getColor(AssetDetailActivity.this, R.color.crush_red));
                        viewCommission.setVisibility(View.VISIBLE);
                        break;
                    case 3:
                        tvPutForward.setTextColor(ContextCompat.getColor(AssetDetailActivity.this, R.color.crush_red));
                        viewForward.setVisibility(View.VISIBLE);
                        break;
                    case 4:
                        tvConsumption.setTextColor(ContextCompat.getColor(AssetDetailActivity.this, R.color.crush_red));
                        viewConsumption.setVisibility(View.VISIBLE);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
    }

    private void releaseView() {
        tvAll.setTextColor(ContextCompat.getColor(this, R.color.nomal));
        viewAll.setVisibility(View.INVISIBLE);

        tvCommission.setTextColor(ContextCompat.getColor(this, R.color.nomal));
        viewCommission.setVisibility(View.INVISIBLE);

        tvConsumption.setTextColor(ContextCompat.getColor(this, R.color.nomal));
        viewConsumption.setVisibility(View.INVISIBLE);

        tvPutForward.setTextColor(ContextCompat.getColor(this, R.color.nomal));
        viewForward.setVisibility(View.INVISIBLE);

        tvReward.setTextColor(ContextCompat.getColor(this, R.color.nomal));
        viewReward.setVisibility(View.INVISIBLE);


    }

    @OnClick({R.id.img_back, R.id.tv_all, R.id.tv_reward, R.id.tv_commission, R.id.tv_put_forward, R.id.tv_consumption})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.tv_all:
                viewPage.setCurrentItem(0);
                break;
            case R.id.tv_reward:
                viewPage.setCurrentItem(1);
                break;
            case R.id.tv_commission:
                viewPage.setCurrentItem(2);
                break;
            case R.id.tv_put_forward:
                viewPage.setCurrentItem(3);
                break;
            case R.id.tv_consumption:
                viewPage.setCurrentItem(4);
                break;
        }
    }
}
